import { Component, Prop, Vue } from 'vue-property-decorator';
import axios from '@axios/project';
import Tag from '@tag'
import TagSelector from './tag_selector/Index.vue';
import { ProjectTag } from '@entity/project';

@Component({
    components: {
        Tag, TagSelector
    }
})
export class AddTagComponent extends Vue {

    /**
     * 添加成员对话框
     */
    private memberTagModal: boolean = false;

    /**
     * 选择项目发布人职位对话框
     */
    private masterTagModal: boolean = false;

    /**
     * 数据库中的职位
     */
    private positionSources: Array<ProjectTag> = [];

    /**
     * 选中的职位
     */
    private selectedPositions: Array<ProjectTag> = [];

    /**
     * 项目发布人职位
     */
    private masterTag: ProjectTag = new ProjectTag();

    @Prop({
        default: 1
    })
    /**人数限制 */
    private memberLimit: number;

    /**
     * 要从数据库中读取有些什么职位
     */
    created() {
        axios.base.getTags().then((res: Array<string>) => {
            res.forEach((item: string) => {
                let tag: ProjectTag = new ProjectTag();
                tag.tag = item;
                this.positionSources.push(tag);
            })
        })
    }

    /**
     * 在数据发生变化时通知父组件
     * 传递的数据包括自己的职位, 组员的职位
     */
    private selectChange(data: any) {
        if (data.mode === 'GROUP') {
            this.selectedPositions = data.list;
        } else {
            this.masterTag = data.list[0];
        }
        this.$emit('on-change', {
            masterTag: this.masterTag,
            positions: this.selectedPositions
        })
    }

}